using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace WindowsGame2
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        VertexPositionColor[] cubo;
        VertexPositionColor[] plano;
       
        VertexBuffer vertexBuffer;

        Matrix world;
        Matrix view;
        Matrix projection;

        BasicEffect effect;

        

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            graphics.PreferredBackBufferHeight = 720;
            graphics.PreferredBackBufferWidth = 1280;

            world = Matrix.Identity;
            view = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up);
            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Window.ClientBounds.Width /(float)Window.ClientBounds.Height, 1, 100);

            //GraphicsDevice.RasterizerState = RasterizerState.CullNone;

            int n = 13;
            cubo = new VertexPositionColor[n];
            cubo[0] = new VertexPositionColor(new Vector3(-1, -1, 1), Color.Black);//a
            cubo[1] = new VertexPositionColor(new Vector3(-1, 1, 1), Color.Red);//b
            cubo[2] = new VertexPositionColor(new Vector3(1, -1, 1), Color.Blue);//c
            cubo[3] = new VertexPositionColor(new Vector3(1, 1, 1), Color.Yellow);//d
            cubo[4] = new VertexPositionColor(new Vector3(1, -1, -1), Color.BlueViolet);//e
            cubo[5] = new VertexPositionColor(new Vector3(1, 1, -1), Color.Fuchsia);//f
            cubo[6] = new VertexPositionColor(new Vector3(-1, -1, -1), Color.Gray);//g
            cubo[7] = new VertexPositionColor(new Vector3(-1, 1, -1), Color.Honeydew);//h
            cubo[8] = new VertexPositionColor(new Vector3(-1, -1, 1), Color.Indigo);//i
            cubo[9] = new VertexPositionColor(new Vector3(-1, 1, 1), Color.CadetBlue);//j
            cubo[10] = new VertexPositionColor(new Vector3(-1, 1, -1), Color.Honeydew);//k
            cubo[11] = new VertexPositionColor(new Vector3(1, 1, 1), Color.YellowGreen);//l
            cubo[12] = new VertexPositionColor(new Vector3(1, 1, -1), Color.MediumOrchid);//m
      
            
            //Plano
            plano = new VertexPositionColor[4];
            plano[0] =new VertexPositionColor(new Vector3(-2,-1,2),Color.Black);//a'
            plano[1] =new VertexPositionColor(new Vector3(-2,-1,-2),Color.Black);//b'
            plano[2] = new VertexPositionColor(new Vector3(2,-1,2), Color.Black);//c'
            plano[3] = new VertexPositionColor(new Vector3(2, -1, -2), Color.Black);//d'



        }

        protected override void Initialize()
        {
            base.Initialize();


            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), cubo.Length, BufferUsage.None);
            vertexBuffer.SetData<VertexPositionColor>(cubo);

            effect = new BasicEffect(GraphicsDevice);

            
     

            IsMouseVisible = true;
        }

        protected override void LoadContent()
        {

            spriteBatch = new SpriteBatch(GraphicsDevice);

        }

      
        protected override void UnloadContent()
        {
            
        }

       
        protected override void Update(GameTime gameTime)
        {
           
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();


            //Camera Rotation
           // world *= Matrix.CreateRotationX(0.01f);
             world *= Matrix.CreateRotationY(0.01f);
            // world *= Matrix.CreateRotationZ(0.05f);





            base.Update(gameTime);
        }



     
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.RasterizerState = RasterizerState.CullNone;

            GraphicsDevice.Clear(Color.White);

            GraphicsDevice.SetVertexBuffer(vertexBuffer);
            effect.World = this.world;
            effect.View = this.view;
            effect.Projection = this.projection;
            effect.VertexColorEnabled = true;
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                GraphicsDevice.DrawUserPrimitives<VertexPositionColor>
                (PrimitiveType.TriangleStrip, cubo, 0,11);
            }

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
             pass.Apply();
                GraphicsDevice.DrawUserPrimitives<VertexPositionColor>
                (PrimitiveType.TriangleStrip, plano, 0, 2);
            
            }

          /* foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                GraphicsDevice.DrawUserPrimitives<VertexPositionColor>
                (PrimitiveType.TriangleStrip, cubo01, 0, 2);
               
            }

           foreach (EffectPass pass in effect.CurrentTechnique.Passes)
           {
               pass.Apply();
               GraphicsDevice.DrawUserPrimitives<VertexPositionColor>
               (PrimitiveType.TriangleStrip, cubo02, 0, 2);

           }*/

            base.Draw(gameTime);
        }
    }
}
